﻿
using Unity.Burst;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;

public struct dotscomp_rangemove : IComponentData
{
    public float3 initpos;
    public float range;
    public float3 newdir;
}

//这个partial 就很耐人寻味，jobs 会自动帮我们插入代码
[BurstCompile]
partial struct jobs_rangemove : IJobEntity
{
    public ThreadRandom trandom;
    public void Execute(ref LocalTransform tran, dotscomp_rangemove comp)
    {
        comp.newdir = math.normalize(new float3(trandom.NextFloat(), 0, trandom.NextFloat()));

        var targetpos = comp.initpos + comp.newdir * comp.range;
        tran.Position = targetpos;

       

    }
}
